package com.dhemery.mack.gui;

import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;

import com.dhemery.mack.adapters.EditorLauncher;
import com.dhemery.mack.model.Node;

//TODO Test this class
public class DoubleClickHandler implements IDoubleClickListener {
	private final StructuredViewer viewer;
	private final EditorLauncher launcher;

	public DoubleClickHandler(StructuredViewer viewer, EditorLauncher launcher) {
		this.viewer = viewer;
		this.launcher = launcher;
		viewer.addDoubleClickListener(this);
	}

	public void dispose() {
		viewer.removeDoubleClickListener(this);
	}

	public void doubleClick(DoubleClickEvent event) {
		IStructuredSelection selection = (IStructuredSelection)event.getSelection();
		launcher.edit((Node)selection.getFirstElement());
	}
}
